package com.yyx.app1.DiagnosticTools_function.Control.ViewPager;

import android.content.Context;
import android.graphics.Color;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.widget.TextView;

import com.yyx.app1.CommonControls.ViewPager_SelectButton;
import com.yyx.app1.R;

import org.androidannotations.annotations.EView;

import java.util.List;

/**
 * Created by yuexing on 2015/9/9.
 */
@EView
public class DiagnosticTools_4function_ViewPager extends ViewPager {
    private int oldPosition;
    private Context context;

    public DiagnosticTools_4function_ViewPager(Context context) {
        super(context);
        this.context=context;
    }

    public DiagnosticTools_4function_ViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context=context;
    }

    public void init(final ViewPager_SelectButton[] buttons, final int[] images, final int[] select, final int begincolor, final int aftercolor) throws Exception {
        DiagnosticTools_4function_ViewPager_Adapter adapter =new DiagnosticTools_4function_ViewPager_Adapter(context);
        adapter.setData();
        setAdapter(adapter);
        if (buttons.length==4)
        {
            this.addOnPageChangeListener(new OnPageChangeListener() {
                @Override
                public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

                }

                @Override
                public void onPageSelected(int position) {
                    buttons[position].getButton_viewpager_text().setTextColor(aftercolor);
                    buttons[position].getButton_viewpager_image().setImageResource(select[position]);
                    buttons[oldPosition].getButton_viewpager_text().setTextColor(begincolor);
                    buttons[oldPosition].getButton_viewpager_image().setImageResource(images[oldPosition]);
                    oldPosition=position;
                }

                @Override
                public void onPageScrollStateChanged(int state) {

                }
            });
        }
        else
        {
            Exception e = new Exception("数量必须为4");
            throw e;
        }
    }
}
